# leetcdoe 404 左叶子之和

# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def sumOfLeftLeaves(self, root: Optional[TreeNode]) -> int:
        self.result = 0
        def iter(node):
            if not node:
                return 0
            if node.left and (node.left.left is None and node.left.right is None):
                self.result += node.left.val
            iter(node.left)
            iter(node.right)
        iter(root)
        return self.result
